@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">抽奖记录</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-6 col-md-7" style="margin-bottom: 10px">

                                        </div>
                                        <div class="col-lg-6 col-md-5">
                                            <div class="input-group">
                                                <input type="text" class="form-control" id="search" value="{{$_GET['search'] ?? ''}}" placeholder="unionid">
                                                <select id="status-val" class="form-control">
                                                    <option value="" @if (empty($_GET['status'])) selected @endif>全部状态</option>
                                                    <option value="2" @if (!empty($_GET['status']) && $_GET['status'] == 2) selected @endif>待处理</option>
                                                    <option value="1" @if (!empty($_GET['status']) && $_GET['status'] == 1) selected @endif>已处理</option>
                                                    <option value="3" @if (!empty($_GET['status']) && $_GET['status'] == 3) selected @endif>已反馈</option>
                                                </select>
                                                <select id="luck-val" class="form-control">
                                                    <option value="" @if (empty($_GET['is_luck'])) selected @endif>不限中奖</option>
                                                    <option value="2" @if (!empty($_GET['is_luck']) && $_GET['is_luck'] == 2) selected @endif>未中奖</option>
                                                    <option value="1" @if (!empty($_GET['is_luck']) && $_GET['is_luck'] == 1) selected @endif>中奖</option>
                                                </select>
                                                <button class="btn btn-primary"
                                                        onclick="window.location.href = '{{ route('admin.draw.log') }}?status='+$('#status-val').val() + '&' + 'is_luck='+$('#luck-val').val() + '&'+ 'search='+$('#search').val()">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table class="table table-sm table-hover text-center">
                                        <thead>
                                        <tr>
                                            <th style="min-width:50px;">ID</th>
                                            <th style="min-width:135px;">抽奖人</th>
                                            <th style="min-width:135px;">奖品名称</th>
                                            <th style="min-width:165px;">抽奖时间</th>
                                            <th style="min-width:50px;">是否中奖</th>
                                            <th style="min-width:160px;">奖励金额</th>
                                            <th style="min-width:160px;">游戏账号</th>
                                            <th style="min-width:160px;">游戏名称</th>
{{--                                            <th style="min-width:160px;">游戏区服</th>--}}
                                            <th style="min-width:120px;">是否处理</th>
                                            <th style="min-width:165px;">处理时间</th>
                                            <th style="min-width:180px;">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($draw as $item)
                                            <tr>
                                                <td>{{$item->id}}</td>
                                                <td>{{$item->unionid}}</td>
                                                <td>{{$item->title}}</td>
                                                <td>{{$item->create_time}}</td>
                                                <td>{{$item->is_luck == 1 ? '是' : '否'}}</td>
                                                <td>{{$item->money}}</td>
                                                <td>{{$item->game_num ? $item->game_num : '-'}}</td>
                                                <td>{{$item->game_url ? $item->game_url.'('.$item->game_server.')' : '-'}}</td>
{{--                                                <td>{{$item->game_server ? ($item->date . '-' . isAfter16($item)) : '-'}}</td>--}}
                                                <td>
                                                    @if ($item->status == 1) 已处理 @endif
                                                    @if ($item->status == 2) 待处理 @endif
                                                    @if ($item->status == 3) 已反馈 @endif
                                                </td>
                                                <td>{{$item->handle_time ? $item->handle_time : '-'}}</td>
                                                <td>
                                                    @if ($item->status == 2 && $item->is_luck == 1)
                                                    <a href="javascript:void(0);" class="btn btn-primary btn-sm" onclick="handleDraw({{$item->id}})">处理</a>
                                                    <a href="javascript:void(0);" class="btn btn-danger btn-sm" onclick="setMsg({{$item->id}})">反馈</a>
                                                    <a href="javascript:void(0);" class="btn btn-info btn-sm" onclick="shuaHao({{$item->id}})">刷号</a>
                                                    @endif
                                                    @if ($item->status == 3)
                                                        {{$item->msg}}
                                                    @endif
                                                </td>
                                            </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                </div>

                            </div> <!-- .card-body -->

                        </div> <!-- .card -->

                        <!-- 分页 -->
                        <nav class="page-card-pagination">
                            <ul class="pagination justify-content-center">
                                {{$draw->Links()}}
                            </ul>
                        </nav>
                        <!-- end分页 -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>
        let isLoading = false;
        //处理
        function handleDraw(id) {
            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{route('admin.draw.handleDraw','').'/'}}'+id)
                    .then(function (response) {
                        isLoading = false;
                        window.location.reload()
                        // toast_tip2(response.data.message, window.location.href);
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }

        }

        function setMsg(id) {
            layer.prompt({title: '输入反馈信息', formType: 2}, function(pass, index){
                axios.post('{{route('admin.draw.setMsg','')}}', {msg: pass, id})
                    .then(function (response) {
                        window.location.reload()
                        // toast_tip2(response.data.message, window.location.href);
                    })
                    .catch(function (error) {
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
                layer.close(index);
            });
        }

        // 刷号
        function shuaHao(id) {
            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{route('admin.draw.shuaHao','').'/'}}'+id)
                    .then(function (response) {
                        isLoading = false;
                        window.location.reload()
                        // toast_tip2(response.data.message, window.location.href);
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }

        }
    </script>
    </body>

@endsection
